__author__ = "Alex, Darren"

from ChessBoard import *
import unittest

class TestParseTextMove(unittest.TestCase):
    """Class by Alex and Darren
       run with python -m unittest TestParseTextMove
    """
    def setUp(self):
        self.chessboard=ChessBoard()

    def __assertChessMoveEqual(self, arg, move):
        self.assertEqual(self.chessboard._parseTextMove(arg), move)
        

    def test_emptyString(self):
        self.assertIsNone(self.chessboard._parseTextMove(""))	

    def test_specialOOTurn0(self):
        self.assertEqual(self.chessboard._turn, 0)
        self.__assertChessMoveEqual("O-O", (None, 4, 7, 6, 7, None))

    def test_special00Turn1(self):
        """Assumed ChessConsts.BLACK=1 and ChessConsts.WHITE=0.
        These constants should be used, but the tested function is using them iether.
        """
        self.chessboard._turn = 1
        self.__assertChessMoveEqual("O-O", (None, 4, 0, 6, 0, None))
	
    def test_specialOOOTurn0(self):
        self.assertEqual(self.chessboard._turn, 0)
        self.__assertChessMoveEqual("O-O-O", (None, 4, 7, 2, 7, None))
   
    def test_invalidCharset(self):
        invalidCharset = "ACDEFGHIJLMOPSTUVWXYZijklmnopqrstuvwxyz90"
        self.assertIsNone(self.chessboard._parseTextMove(invalidCharset))

    def test_validNotationAN(self):
	self.__assertChessMoveEqual("e2e4", (None, 4, 6, 4, 4, None))
	self.__assertChessMoveEqual("f1d2", (None, 5, 7, 3, 6, None))
	self.__assertChessMoveEqual("d7-d8", (None, 3, 1, 3, 0, None))
	self.__assertChessMoveEqual("g1-f3", (None, 6, 7, 5, 5, None))

    def test_validNotationSAN(self):
	self.__assertChessMoveEqual("e4", ('P', -1, -1, 4, 4, None))
	self.__assertChessMoveEqual("Rfxd1", ('R', 5, -1, 3, 7, None))
	self.__assertChessMoveEqual("d8=Q", ('P', -1, -1, 3, 0, 1))
	self.__assertChessMoveEqual("Nxf3+", ('N', -1, -1, 5, 5, None))

    def test_validNotationLAN(self):
	self.__assertChessMoveEqual("Pe2e4", (None, 4, 6, 4, 4, None))
	self.__assertChessMoveEqual("Rf1xd1", (None, 5, 7, 3, 7, None))
	self.__assertChessMoveEqual("Pd7d8=Q", (None, 3, 1, 3, 0, 1))
	self.__assertChessMoveEqual("Ng1xf3+", (None, 6, 7, 5, 5, None))

